#!/bin/bash
if [ "$1" = "" ];then
echo "Company Empty"
exit -1
fi
if [ "$2" = "" ];then
echo "Page Empty"
exit -1
fi
company=$1
page=$2

page_num=1
while [ 1 ]
do
wget "http://www.104.com.tw/jobbank/custjob/index.php?r=cust&jobsource=104comlist&j=$company&page=$page#info06" -O tmp -o log --max-redirect=0
sleep 2
jobCnt=`grep jobname tmp | wc -l`
urgentCnt=`grep icon_urgency tmp | wc -l`
jobCnt=`expr $jobCnt - $urgentCnt`
if [ $jobCnt -lt 1 ];then
	echo "There may have something wrong. Company $company Page $page"
	mv tmp problem_page_$$
	exit -1 
fi
if [ $jobCnt -lt 4 ];then
	echo "Exit normally"
	exit 0
fi
mv tmp "page$page"
page=`expr $page + 1`
done
